/*************************************************************************
	> File Name: main.c
	> Author: ycst
	> Mail: a1277992967@163.com 
	> blog: http://www.ycst.club/suggest/
	> Created Time: 2022/7/4 9:24:22
 ************************************************************************/
#include "fun.h"

int main(int argc, char* argv[]){
	int Start_or_not = 0;
	int Keep_or_not = 0;
	int x = 0, y = 0, temp = 0;
	int Time = 0;
	int Minute_start = 0, Second_start = 0;
	int Minute_end = 0, Second_end = 0;
	int Max_Hit_Man1 = 0, Max_Hit_Man2 = 0, Max_Hit_Robot = 0;


	srand((unsigned)time(NULL));
	int map[WIDTH][HEIGHT] = {0};


	time_t timep;
	struct tm *p;
	time(&timep);
	p = gmtime(&timep);
	

	
Start:
	Minute_start = p->tm_min;
	Second_start = p->tm_sec;
	system("color 0F");
	Init(map);	
	Welcome();

	scanf("%d", &Start_or_not);
	if (Start_or_not != 1 && Start_or_not != 2 && Start_or_not!= 3) {
		Good_Bye();
		return 0;
	}
	Refresh(map);

	if (Start_or_not == 1) {
		while (1) {
		P1:
			system("color 0F");
			puts("Please P1 input X and Y\n");
			printf(": ");
			scanf("%d %d", &x, &y);
			temp = Check_Input(map, x, y);
			if (temp == Wrong) {
				puts("Please input X and Y between [0, 15]\n");
				goto P1;
			}
			if (temp == Already_exists) {
				puts("This area is already in use\n");
				goto P1;
			}
			Input_Man1(map, x, y);
			Refresh(map);
			Keep_or_not = Check_All(map);
			if (Keep_or_not == Finish) {
				Twinkle();
				Shining_char(map, Man1);
				Time_Counter(Minute_start, Second_start);
				//Max_Hit_Man1 = Scoring_Man1(map);
				Max_Hit_Man2 = Scoring_Man2(map);
				printf("P1 Score : %d \n", 5);
				printf("P2 Score : %d \n", Max_Hit_Man2);

				puts("Play again?\n");
				puts("YES : 1");
				puts("NO : 2 or else");
				scanf("%d", &Start_or_not);
				if (Start_or_not != 1)return 0;
				Refresh(map);
				goto Start;
			}
		P2:
			system("color F0");
			puts("Please P2 input X and Y\n");
			printf(": ");
			scanf("%d %d", &x, &y);
			temp = Check_Input(map, x, y);
			if (temp == Wrong) {
				puts("Please input X and Y between [0, 15]\n");
				goto P2;
			}
			if (temp == Already_exists) {
				puts("This area is already in use\n");
				goto P2;
			}
			Input_Man2(map, x, y);
			Refresh(map);
			Keep_or_not = Check_All(map);
			if (Keep_or_not == Finish) {
				Twinkle();
				Shining_char(map, Man2);
				Time_Counter(Minute_start, Second_start);
				Max_Hit_Man1 = Scoring_Man1(map);
				//Max_Hit_Man2 = Scoring_Man2(map);
				printf("P1 Score : %d \n", Max_Hit_Man1);
				printf("P2 Score : %d \n", 5);

				puts("Play again?\n");
				puts("YES : 1");
				puts("NO : 2 or else");
				scanf("%d", &Start_or_not);
				if (Start_or_not != 1)return 0;
				Refresh(map);
				goto Start;
			}
		}
	}


	if (Start_or_not == 2) {
		while (1) {
		P3:
			system("color 0F");
			puts("Please P1 input X and Y\n");
			printf(": ");
			scanf("%d %d", &x, &y);
			temp = Check_Input(map, x, y);
			if (temp == Wrong) {
				puts("Please input X and Y between [0, 15]\n");
				goto P3;
			}
			if (temp == Already_exists) {
				puts("This area is already in use\n");
				goto P3;
			}
			Input_Man1(map, x, y);
			Refresh(map);
			Keep_or_not = Check_All(map);
			if (Keep_or_not == Finish) {
				Twinkle();
				Shining_char(map, Man1);
				Time_Counter(Minute_start, Second_start);
				//Max_Hit_Man1 = Scoring_Man1(map);
				Max_Hit_Robot = Scoring_Robot(map);
				printf("P1 Score : %d \n", 5);
				printf("Robot Score : %d \n", Max_Hit_Robot);

				puts("Play again?\n");
				puts("YES : 1");
				puts("NO : 2 or else");
				scanf("%d", &Start_or_not);
				if (Start_or_not != 1)return 0;
				Refresh(map);
				goto Start;

			}
		P4:
			system("color F0");
			puts("Robot is thinking\n");

			Input_Rebot_Hard(map);
			Refresh(map);
			Keep_or_not = Check_All(map);
			if (Keep_or_not == Finish) {
				Twinkle();
				Shining_char(map, Robot);
				Time_Counter(Minute_start, Second_start);
				Max_Hit_Man1 = Scoring_Man1(map);
				//Max_Hit_Robot = Scoring_Robot(map);
				printf("P1 Score : %d \n", Max_Hit_Man1);
				printf("Robot Score : %d \n", 5);

				puts("Play again?\n");
				puts("YES : 1");
				puts("NO : 2 or else");
				scanf("%d", &Start_or_not);
				if (Start_or_not != 1)return 0;
				Refresh(map);
				goto Start;

			}
		}
	}

	if (Start_or_not == 3) {
		while (1) {
		P5:
			system("color 0F");
			puts("Please P1 input X and Y\n");
			printf(": ");
			scanf("%d %d", &x, &y);
			temp = Check_Input(map, x, y);
			if (temp == Wrong) {
				puts("Please input X and Y between [0, 15]\n");
				goto P5;
			}
			if (temp == Already_exists) {
				puts("This area is already in use\n");
				goto P5;
			}
			Input_Man1(map, x, y);
			Refresh(map);
			Keep_or_not = Check_All(map);
			if (Keep_or_not == Finish) {
				Twinkle();
				Shining_char(map, Man1);
				Time_Counter(Minute_start, Second_start);
				//Max_Hit_Man1 = Scoring_Man1(map);
				Max_Hit_Robot = Scoring_Robot(map);
				printf("P1 Score : %d \n", 5);
				printf("Robot Score : %d \n", Max_Hit_Robot);

				puts("Play again?\n");
				puts("YES : 1");
				puts("NO : 2 or else");
				scanf("%d", &Start_or_not);
				if (Start_or_not != 1)return 0;
				Refresh(map);
				goto Start;

			}
		P6:
			system("color F0");
			puts("Robot is thinking\n");

			Input_Rebot_Easy(map);
			Refresh(map);
			Keep_or_not = Check_All(map);
			if (Keep_or_not == Finish) {
				Twinkle();
				Shining_char(map, Robot);
				Time_Counter(Minute_start, Second_start);
				Max_Hit_Man1 = Scoring_Man1(map);
				//Max_Hit_Robot = Scoring_Robot(map);
				printf("P1 Score : %d \n", Max_Hit_Man1);
				printf("Robot Score : %d \n", 5);

				puts("Play again?\n");
				puts("YES : 1");
				puts("NO : 2 or else");
				scanf("%d", &Start_or_not);
				if (Start_or_not != 1)return 0;
				Refresh(map);
				goto Start;

			}
		}
	}
	return 0;
}

